package cn.school.controller.workmgr;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.workmgr.entity.RecruitBanner;
import cn.school.workmgr.entity.RecruitMajor;
import cn.school.workmgr.service.RecruitBannerService;
import cn.school.workmgr.service.RecruitMajorService;
import cn.school.workmgr.vo.RecruitBannerVO;
import cn.school.workmgr.vo.RecruitMajorVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "招生banner")
@RequestMapping("/workmgr/banner")
public class RecruitBannerController {
    @Resource
    private RecruitBannerService recruitBannerService;

    @ApiOperation("分页查询")
    @PostMapping("/pageList")
    public CommonResult<CommonPage<RecruitBanner>> list(@RequestBody RecruitBannerVO vo) {
        IPage<RecruitBanner> recruitMajorIPage = recruitBannerService.pageList(vo);
        return CommonResult.success(CommonPage.restPage(recruitMajorIPage));
    }

    @ApiOperation("新增或修改")
    @PostMapping("/addOrUpdate")
    public CommonResult<Integer> addOrUpdate(@RequestBody RecruitBanner entity) {
        int num  = recruitBannerService.addOrUpdateMajor(entity);
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("删除单个")
    @PostMapping("/deleteById")
    public CommonResult<CommonPage<RecruitMajor>> deleteById(@RequestBody RecruitBanner entity) {
        int num  = recruitBannerService.deleteById(entity.getId()+"");
        if(num>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("查询banner列表")
    @GetMapping("/list/{tenantId}")
    public CommonResult<List<RecruitBanner>> bannerList(@PathVariable("tenantId")String tenantId) {
        List<RecruitBanner> list = recruitBannerService.bannerList(tenantId);
        return CommonResult.success(list);
    }
}
